<!--
 * @Date: 2024-12-11 16:13:30
 * @Author: ljc
 * @LastEditors: g05047
 * @LastEditTime: 2025-02-26 16:48:17
 * @Description: 饼状配置面板
-->
<template>
  <div>
    <el-button :plain="true"
      round
      type="primary"
      size="small"
      @click="handleOpen">编辑</el-button>
  </div>
</template>

<script setup>
import { callComp } from '@/plugins/call-comp/CallCompPlugins.jsx'
import SeriesPieDialog from './components/SeriesPieDialog.vue'
import { useDbSourceStore } from '@hp/stores/store-dbsource.js'
const emits = defineEmits(['update:modelValue'])
// 数据集
const dbSourceStore = useDbSourceStore()
const props = defineProps({
  row: { type: Object },
  schema: { type: Object },
  config: { type: Object },
  modelValue: Array
})
/**
 * 打开编辑面板
 */
const handleOpen = () => {
  const data = dbSourceStore.getDbSourceDic(props.schema.id)
  const isArray = data instanceof Array;
  const attrs = {
    ...props,
    modelData: isArray ? data : [],
  }
  delete attrs.modelValue
  callComp.open(SeriesPieDialog, {
    ...attrs,
    onConfirm: (res) => {
      handleEchartData(res)
    }
  })
}
/**
 * 
 * @param result {Array} 处理color 和 path
 */
const handleEchartData = (result) => {
  let colors = []
  let pathList = []
  result.forEach(item => {
    colors.push(item.color)
    pathList.push({
      path: item.path,
      params: item.params,
    })
  })
  props.schema.pathList = pathList
  emits('update:modelValue', colors)
}
</script>
<style lang="scss" scoped>
</style>